<template>
  <headerView ref="header" systemName="统一身份认证平台" />
  <div class="app-table">
    <div class="app-body">
      <div class="app-separator">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/' }">主页</el-breadcrumb-item>
          <el-breadcrumb-item><a>通知公告</a></el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <el-divider></el-divider>

      <div class="article-list">
        <div v-for="(item, index) in list" @click="detail(item.id)" :key="item.id">
          <el-link>{{ index + 1 }}、{{ item.title }} | {{ item.publishDate }}</el-link>

          <el-divider></el-divider>
        </div>
      </div>
      <el-config-provider :locale="locale">
        <el-pagination background="white" :total="total" :page-size="limit"
          :page-sizes="[2, 5, 10, 20, 30, 40, 50, 100]" layout="total, sizes, prev, pager, next, jumper"
          @size-change="changePageSize" @current-change="changeCurrentPage">
        </el-pagination>
      </el-config-provider>
    </div>
  </div>
  <bottomView />
</template>
<script>
import headerView from "@/components/header.vue";
import bottomView from "@/components/bottom.vue";

import {
  ElConfigProvider,
  ElMessageBox,
  ElMessage,
  ElLink,
} from "element-plus";
import zhCn from "element-plus/lib/locale/lang/zh-cn";

import { httpService } from "@/utils/httpService";
import { Picture as IconPicture } from "@element-plus/icons-vue";
export default {
  name: "ArticleList",
  data() {
    return {
      list: [],
      pageSize: 5,
      page: 1,
      total: 0,
      pageCount: 0,
      form: {
        appName: "",
        type: "",
      },
    };
  },
  mounted() {
    // this.$refs.header.systemName = "统一身份认证平台";
    this.$refs.header.homeIndexName = "Index";
    this.getListArticle();
  },

  components: {
    headerView,
    IconPicture,
    ElConfigProvider,
    ElMessageBox,
    ElMessage,
    bottomView,
    ElLink,
  },
  setup() {
    return {
      locale: zhCn,
    };
  },
  methods: {
    getListArticle() {
      httpService(
        "/javaApi/baseArticle/list/" + this.page + "/" + this.pageSize,
        "",
        "get"
      ).then((data) => {
        this.list = data.object.list;
        this.total = data.object.total;
        this.pageCount = data.object.pages;
      });
    },
    // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
    changePageSize(size) {
      this.pageSize = size;
      this.getListArticle();
    },

    // 改变页码，page：回调参数，表示当前选中的“页码”
    changeCurrentPage(page) {
      this.page = page;
      this.getListArticle();
    },
    tableRowClassName({ row, rowIndex }) {
      return "";
    },
    detail(id) {
      this.$router.push({ name: "ArticleDetail", query: { "id": id } });
    },
  },
};
</script>

<style>
.article-list {
  min-height: calc(100vh - 370px);
}

.app-table {
  background: #eff3f5;
  padding: 10px;
}

.app-search {
  margin-left: 10px;
  margin-top: 10px;
}

.app-separator {
  padding-top: 10px;
  padding-bottom: 10px;
  padding-left: 10px;
}

.app-body {
  background: white;
  padding: 20px;
}

.el-table .warning-row {
  --el-table-tr-bg-color: var(--el-color-warning-lighter);
}

.el-table .success-row {
  --el-table-tr-bg-color: var(--el-color-success-lighter);
}

.el-pagination {
  text-align: center;
  margin-top: 20px;
  margin-bottom: 10px;
}
</style>
